package com.jarvis.pzz.modules.buyshop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.jarvis.pzz.R;
import com.jarvis.pzz.modules.findshop.model.FindFacilitiesModel;
import com.jarvis.pzz.util.ViewHolderUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/9/14 0014.
 */

public class BuyShopAdapter extends BaseAdapter {
    private List<FindFacilitiesModel> list;
    private Context context;

    public BuyShopAdapter(List<FindFacilitiesModel> list, Context context) {
        this.context = context;
        this.list = list;
    }
    public void notifyDataSetChanged(List<FindFacilitiesModel> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
      final FindFacilitiesModel findFacilitiesModel = list.get(position);
        convertView = LayoutInflater.from(context).inflate(R.layout.item_findshop, null);
        ImageView imageView = ViewHolderUtil.get(convertView, R.id.iv_img);
        if (findFacilitiesModel.isState()) {
            imageView.setImageResource(findFacilitiesModel.getImg_yes());
        } else {
            imageView.setImageResource(findFacilitiesModel.getImg_no());
        }
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(findFacilitiesModel.isState()){
                    list.get(position).setState(false);
                    notifyDataSetChanged(list);
                }else {
                    list.get(position).setState(true);
                    notifyDataSetChanged(list);
                }


            }
        });
        return convertView;
    }
}

